﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace HRWeb.Common
{
    public class GenericEqualityComparer<TE, TV>  : IEqualityComparer<TE>
    {
        private Func<TE, TV> func;
        private Func<TV, TV, bool> compare;

        public GenericEqualityComparer(Func<TE, TV> func, Func<TV, TV, bool> compare)
        {
            this.func = func;
            this.compare = compare;
        }

        #region IEqualityComparer<TE> Members

        public bool Equals(TE x, TE y)
        {
            TV a = func(x);
            TV b = func(y);
            return compare(a, b);
        }

        public int GetHashCode(TE obj)
        {
            return func(obj).GetHashCode();
        }

        #endregion
    }
}
